#include<cstdio>
#include<mysql.h>
#include<unistd.h>
#include"functions.h"
extern MYSQL *mysql;
int sys_2_modify(char *table)
{
	char sc;
	int ID, credit;
	char class_name[50], mysql_modify[100];
	printf("请输入您要修改的课程ID：");
	scanf("%d", &ID);
	sprintf(mysql_modify, "SELECT * FROM %s WHERE ID='%d'", table, ID);
	mysql_query(mysql, mysql_modify);
	MYSQL_RES *res = mysql_store_result(mysql);
	if(mysql_num_rows(res) == 0)
	{	
		fprintf(stderr, "%s\n", mysql_error(mysql));
		printf("无此信息！\n");
		sleep(5);
		return 0;
	}
	else
	{
		MYSQL_ROW row = mysql_fetch_row(res);
		printf("课程ID 课程名 课程学分\n");
		for(unsigned int i = 0; i < mysql_num_fields(res); i++)
		{
			for(int j = printf("  %s",row[i]); j < 7; j ++)	putchar(' ');
		}
		mysql_free_result(res);
		printf("\n请输入您要修改的课程名和课程学分:");
		scanf("%s %d", class_name, &credit);
		sprintf(mysql_modify, "UPDATE %s SET class_name='%s',credit='%d' WHERE ID='%d'", table, class_name, credit, ID);
		if(!sys_error(mysql_modify))
			return 0;
	}
	printf("输入回车结束 ");
	scanf("%c", &sc); scanf("%c", &sc);
	return 1;
}
